package org.example.chatroom.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.chatroom.common.pojo.request.AddFriendRequest;
import org.example.chatroom.common.pojo.request.FriendSearchRequest;
import org.example.chatroom.common.pojo.request.LoginRequest;
import org.example.chatroom.common.pojo.request.RegisterRequest;
import org.example.chatroom.common.pojo.response.*;
import org.example.chatroom.service.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2025-06-21
 * Time: 17:29
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;

    @Resource(name = "friendServiceImpl")
    private FriendService friendService;

    @Resource(name = "dialogueServiceImpl")
    private DialogueService dialogueService;

    @Resource(name = "messageServiceImpl")
    private MessageService messageService;

    @Resource(name = "friendRequestServiceImpl")
    private FriendRequestService friendRequestService;

    @RequestMapping("/register")
    public boolean register(@RequestBody RegisterRequest user){
        return userService.register(user);
    }
    @RequestMapping("/login")
    public LoginResponse login(@RequestBody LoginRequest user){
        return userService.login(user);
    }
    @RequestMapping("/getfriendlist")
    public List<FriendResponse> getfriendlist(Integer userId){
        return friendService.getfriendlist(userId);
    }
    @RequestMapping("/getdialoguelist")
    public List<DialogueResponse> getdialoguelist(Integer userId){
        return dialogueService.getdialoguelist(userId);
    }
    //通过userId获得头像
    @RequestMapping("/getavatarUrl")
    public String getavatarUrl(Integer userId){
        return userService.getavatarUrl(userId);
    }
    @RequestMapping("/getfrienddialogue")
    public Integer getfrienddialogue (Integer userId,Integer friendId){
        return dialogueService.getfrienddialogue(userId,friendId);
    }
    @RequestMapping("/getmessage")
    public List<MessageResponse> getmessage(Integer dialogueId){
        return messageService.getmessage(dialogueId);
    }

    @RequestMapping("/searchFriends")
    public List<FriendSearchResponse> searchFriends(@RequestBody FriendSearchRequest request) {
        return friendService.searchFriends(request);
    }

//    @RequestMapping("/sendFriendRequest")
//    public void sendFriendRequest(Integer fromUserId, @RequestBody AddFriendRequest request) {
//        friendService.sendFriendRequest(fromUserId, request);
//    }

    @RequestMapping("/handleFriendRequest")
    public void handleFriendRequest(Integer userId, Integer friendRequestId, String action) {
        friendService.handleFriendRequest(userId, friendRequestId, action);
    }
    @RequestMapping("/getUserList")
    public FriendResponse getUserList(String telephone){
        return userService.getUserList(telephone);
    }
// 获得添加好友列表全部信息（历史记录）
    @RequestMapping("/getRequestMessage")
    public List<RequestMessageResponse> getRequestMessage(Integer userId){
        return friendRequestService.getRequestMessage(userId);
    }
//统一好友请求，改变状态，添加好友
    @RequestMapping("/handleRequest")
    public boolean handleRequest(boolean resp,Integer friendRequestId){
        return friendRequestService.handleRequest(resp,friendRequestId);
    }
    //创建群聊
    @RequestMapping("/createGroup")
    public Integer createGroup(@RequestBody List<Integer> userIds){
        return dialogueService.createGroup(userIds);
    }
}
